<?php
/*
 * 进云智能生成平台
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
 */
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
if($_RQ['op']=='get'){
	$return['title']='下单';
	$member=model('core/member')->detail($_SESSION['uid'],array('credit1','credit2','credit3','credit4','credit6','mobile','avatar','nickname'));
	$feeset=$this->setting['feeset'];
	if(!$feeset){
		$feeset=array(
			array('fee'=>10,'payfee'=>10),
			array('fee'=>20,'payfee'=>20),
			array('fee'=>30,'payfee'=>30),
			array('fee'=>50,'payfee'=>50),
			array('fee'=>100,'payfee'=>100),
			array('fee'=>150,'payfee'=>150),
		);
	}
	$return['post']=array(
		'mobile'=>$member['mobile'],
		'fee'=>$feeset[0]['fee'],
		'payfee'=>$feeset[0]['payfee'],
		'type'=>0,
	);
	$return['member']=$member;
	$return['feeset']=$feeset;
	set_html('title','在线充值');
	exi($return);
}
if($_RQ['op']=='post'){
	//下单
	$post=get_postdata();
	if($_SESSION['uid']){
		//exi('您已登录！无需再注册！','error');
	}
	if(!$post['mobile']){
		exi('请输入手机号！','error');
	}
	if($post['fee']<=0){
		exi('请选择充值额度！','error');
	}
	$feeset=$this->setting['feeset'];
	if(!$feeset){
		$feeset=array(
			array('fee'=>10,'payfee'=>10),
			array('fee'=>20,'payfee'=>20),
			array('fee'=>30,'payfee'=>30),
			array('fee'=>50,'payfee'=>50),
			array('fee'=>100,'payfee'=>100),
			array('fee'=>150,'payfee'=>150),
		);
	}
	$payfee=$post['payfee'];
	$data=array(
		'uniacid'=>$_SESSION['uniacid'],
		'mid'=>$_SESSION['uid'],
		'fee'=>$post['fee'],
		'payfee'=>$payfee,
		'mobile'=>$post['mobile'],
		'createtime'=>TIMESTAMP,
		'status'=>0,
	);
	$this->insert('order',$data);
	$order_id=pdo_insertid();
	$params=array(
			'id'=>$order_id,
			'title'=>'话费充值',
			'fee'=>$payfee,
			'back_url'=>'jy_feemobile/index/payresult/',
			'success_url'=>'jy_feemobile/order/',
			'error_url'=>'jy_feemobile/order/',
	);
	$payid=cfc('pay')->create_pay_order($params);
	$this->pdo_update('order',array('pay_id'=>$payid),array('id'=>$order_id));
	$res=array(
		'pay_id'=>$payid,
		'order_id'=>$order_id,
		'success_url'=>'jy_feemobile/order/',
		'error_url'=>'jy_feemobile/order/',
	);
	exi($res);
}
if($_RQ['op']=='payresult'){
	$payresult=$_SESSION['pay_result'];
	if($payresult['status']!=1 && $payresult['pay_type'] !='hdfk'){
		exi('支付失败。','error','jy_feemobile/order/');
	}
	$order=pdo_get('jy_feemobile_order',array('id'=>$payresult['id']));
	if($order['ispay'] ==1){
		exi('该订单已经支付！','error','jy_feemobile/order/');
	}
	if($order['payfee']!=$payresult['fee']){
		exi('支付失败！订单金额不匹配！'.$order['price'].'|'.$payresult['fee'],'error','jy_feemobile/order/');
	}
	$update=array(
		'paytype'=>$payresult['pay_type'],
		'transid'=>$payresult['transaction_id'],
		'paytime'=>time(),
		'status'=>1,
		'ispay'=>1,
	);
	$this->pdo_update('order',$update,array('id'=>$order['id']));
	exi('提交成功!');
}
?>